package cn.edu.buaa.cnsatm.traffic_big_data_server.highway.dao;

import cn.edu.buaa.cnsatm.traffic_big_data_server.highway.model.HighwayCongestionModel;
import cn.edu.buaa.cnsatm.traffic_big_data_server.util.JDBCUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @name = LX
 * @classname = RoadDAO
 * @description =
 * @date = 2019/12/9
 */
public class RoadDAO {
    public static int insertBeijingRoadName(String roadName) throws SQLException {
        /**
         * @author: LX
         * @methodName: insertBeijingRoadName
         * @description: 背景道路名称数据存入数据库
         * @data: 2019-12-09
         **/
        int insertNum = 0;

        String sql = "INSERT INTO beijing_road_name (road_name) values ('" + roadName + "')";
            Statement stmt = null;
            try {
                stmt = JDBCUtil.databaseConnecttion.createStatement();//创建数据库查询实体
                insertNum = stmt.executeUpdate(sql);//执行Sql查询语句
                System.out.print(sql + "\n");
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                stmt.close();
            }
        return insertNum;
    }
    public static ResultSet  getBeijingRoadName(){
        String sql = "SELECT DISTINCT name FROM beijing_highway WHERE name is not null";
        Statement stmt = null;
        ResultSet resultSet = null;
        try{
            stmt = JDBCUtil.databaseConnecttion.createStatement();
            resultSet = stmt.executeQuery(sql);
        }catch (SQLException e){
            e.printStackTrace();
        }
        return resultSet;
    }
}
